package simonxianyu.learn.springmybatis.svc;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import simonxianyu.learn.springmybatis.util.PasswordEncoder;

/**
 *
 * Created by simon on 2017/2/21.
 */
public class Md5PasswordEncoder implements PasswordEncoder {
  private String salt = null;

  public Md5PasswordEncoder() {
  }

  public Md5PasswordEncoder(String salt) {
    this.salt = salt;
  }

  @Override
  public String encode(String origin) {
    if (salt != null) {
      return DigestUtils.md5Hex(origin+salt);
    }
    return DigestUtils.md5Hex(origin);
  }

  public void setSalt(String salt) {
    this.salt = salt;
  }
}
